home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / viewport / viewport.cpp next >
Encoding:
C/C++ Source or Header  |  2000-03-19  |  2.7 KB  |  142 lines

  1. #include "..\..\lib\Fly3D.h"
  2. #include "viewport.h"
  3.  
  4. viewport_desc cd_viewport;
  5.  
  6. BOOL APIENTRY DllMain(HINSTANCE hModule, 
  7.                       DWORD  ul_reason_for_call, 
  8.                       LPVOID lpReserved)
  9. {    
  10.     switch( ul_reason_for_call ) 
  11.     {
  12.     case DLL_PROCESS_ATTACH:
  13.     case DLL_THREAD_ATTACH:
  14.     case DLL_THREAD_DETACH:
  15.     case DLL_PROCESS_DETACH:
  16.         break;
  17.     }
  18.     return TRUE;
  19. }
  20.  
  21. __declspec( dllexport )
  22. int num_classes()
  23. {
  24.     return 1;
  25. }
  26.  
  27. __declspec( dllexport )
  28. class_desc *get_class_desc(int i)
  29. {
  30.     switch(i)
  31.     {
  32.     case 0:
  33.         return &cd_viewport;
  34.     default: return 0;
  35.     }
  36. }
  37.  
  38. void draw()
  39. {
  40.     int i,nvp=0;
  41.     viewport *vp[16],*v=0;
  42.     while(v=(viewport *)flyengine->get_next_stock_object(v,TYPE_VIEWPORT))
  43.         vp[nvp++]=v;
  44.  
  45.     if (nvp==0) return;
  46.  
  47.     bsp_object *d=flyengine->cam;
  48.  
  49.     for( i=0;i<nvp;i++ )
  50.         if (vp[i]->target && vp[i]->target->node && (vp[i]->on&0xf))
  51.         {
  52.         flyengine->cur_frame++;
  53.         local_system ls=*((local_system *)vp[i]->target);
  54.  
  55.         int x=(int)(vp[i]->xf*screen_sx), 
  56.             y=(int)(vp[i]->yf*screen_sy),
  57.             wx=(int)(vp[i]->sxf*screen_sx),
  58.             wy=(int)(vp[i]->syf*screen_sy);
  59.         glViewport(x,y,wx,wy);
  60.         glScissor(x,y,wx,wy);
  61.         glEnable(GL_SCISSOR_TEST);
  62.         glClear( GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT );
  63.         glDisable(GL_SCISSOR_TEST);
  64.  
  65.         if (vp[i]->dirflag) vp[i]->target->rotate(180,vp[i]->target->Y);
  66.         flyengine->set_camera(vp[i]->target);
  67.         flyengine->draw_bsp();
  68.  
  69.         *((local_system *)vp[i]->target)=ls;
  70.         }
  71.  
  72.     glViewport(0, 0, screen_sx, screen_sy);
  73.  
  74.     flyengine->set_camera(d);
  75.     for( i=0;i<nvp;i++ )
  76.         if (directx->diks[vp[i]->key]&0x80)
  77.             if ((vp[i]->on&0xf0)==0)
  78.                 vp[i]->on=(int)(!vp[i]->on)|0xf0;
  79.             else ;
  80.         else if (vp[i]->on&0xf0) 
  81.                 vp[i]->on=(vp[i]->on&0xf);
  82. }
  83.  
  84. __declspec( dllexport )
  85. int fly_message(int msg,int param,void *data)
  86. {
  87.     switch(msg)
  88.     {
  89.     case FLYM_DRAWSCENE:
  90.         if (directx->mpmode!=FLYMP_SERVER)
  91.             draw();
  92.         break;
  93.     }
  94.     return 1;
  95. }
  96.  
  97. int viewport::get_custom_param_desc(int i,param_desc *pd)
  98. {
  99.     if (pd==0)
  100.         return 7;
  101.     else 
  102.     switch(i)
  103.     {
  104.         case 0:
  105.             pd->type='f';
  106.             pd->data=&xf;
  107.             strcpy(pd->name,"xf");
  108.             break;
  109.         case 1:
  110.             pd->type='f';
  111.             pd->data=&yf;
  112.             strcpy(pd->name,"yf");
  113.             break;
  114.         case 2:
  115.             pd->type='f';
  116.             pd->data=&sxf;
  117.             strcpy(pd->name,"sxf");
  118.             break;
  119.         case 3:
  120.             pd->type='f';
  121.             pd->data=&syf;
  122.             strcpy(pd->name,"syf");
  123.             break;
  124.         case 4:
  125.             pd->type='i';
  126.             pd->data=&dirflag;
  127.             strcpy(pd->name,"dirflag");
  128.             break;
  129.         case 5:
  130.             pd->type='d';
  131.             pd->data=⌖
  132.             strcpy(pd->name,"target");
  133.             break;
  134.         case 6: 
  135.             pd->type='i';
  136.             pd->data=&key;
  137.             strcpy(pd->name,"key");
  138.             break;
  139.     }
  140.     return 0;
  141. }
  142.